#include "stdio.h"
#include "string.h"
char *plus(char a[],char b[]);
char *minus(char a[],char b[]);
main(){
	char a[500],b[500],t[5];
	int i,j,n,n1;
	scanf("%d",&n1);
	for(j=0;j<n1;j++){
		scanf("%s%s%d",a,b,&n);
		strcpy(t,b);
		for(i=1;i<=n;i++){
			if(i%2==1)
				plus(a,b);
			else
				plus(b,a);
		}
		if(n%2==1)
			printf("%s\n",minus(a,t));
		else
			printf("%s\n",minus(b,t));
	}
}
char *plus(char a[],char b[]){
	int c[500]={0},d[500]={0};
	int l1=strlen(a),l2=strlen(b),i,t;
	for(i=l1-1;i>=0;i--){
		c[l1-i-1]=a[i]-'0';
	}
	for(i=l2-1;i>=0;i--){
		d[l2-i-1]=b[i]-'0';
	}
	for(i=0;i<l1;i++)
	l1=l1>l2?l1:l2;
	for(i=0,t=0;i<l1;i++){
		if(d[i]+c[i]+t>=10){
			c[i]=(d[i]+c[i]+t)%10;
			t=1;
		}
		else{
			c[i]=(d[i]+c[i]+t)%10;
			t=0;
		}
	}
	if(t==1)
		c[l1++]=1;
	for(i=l1-1;i>=0;i--){
		a[l1-i-1]=c[i]+'0';
	}
	a[l1]='\0';return a;
}
char *minus(char a[],char b[]){
	int c[500]={0},d[500]={0};
	int l1=strlen(a),l2=strlen(b),i;
	for(i=l1-1;i>=0;i--){
		c[l1-i-1]=a[i]-'0';
	}
	for(i=l2-1;i>=0;i--){
		d[l2-i-1]=b[i]-'0';
	}
	for(i=0;i<l1;i++)
	l1=l1>l2?l1:l2;
	for(i=0;i<l1;i++){
		if(c[i]-d[i]<0){
			c[i]=c[i]-d[i]+10;
			c[i+1]--;
		}
		else
			c[i]-=d[i];
	}
	for(i=l1-1;i>=0;i--){
		a[l1-i-1]=c[i]+'0';
	}
	a[l1]='\0';return a;

}